home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 3 / Amiga Format CD03 (1996-07-04)(Future Publishing)(GB)(Track 1 of 6)[!][issue 1996-08].iso / comms / netsoftware / archie38_1.lha / archie-1.4 / vlalloc.c < prev    next >
C/C++ Source or Header  |  1995-01-05  |  3KB  |  119 lines

  1. /*
  2.  * Copyright (c) 1989, 1990, 1991 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7. /* Amiga port by Tomas Willis (tomas@cae.wisc.edu) January 1995 */
  8.  
  9. #include <stdio.h>
  10.  
  11. #include "pfs.h"
  12. #include "pmachine.h"
  13.  
  14. static VLINK    lfree = NULL;
  15. int        vlink_count = 0;
  16. int        vlink_max = 0;
  17.  
  18. //protos --local
  19. VLINK vlalloc(void);
  20. void vlfree(VLINK vl);
  21. void vllfree(VLINK vl);
  22.  
  23. //protos --extern
  24. extern void atlfree( PATTRIB at);
  25. extern void stfree(char *st);
  26. extern char * stcopy(char *st);
  27.  
  28. /*
  29.  * vlalloc - allocate and initialize vlink structure
  30.  *
  31.  *    VLALLOC returns a pointer to an initialized structure of type
  32.  *    VLINK.  If it is unable to allocate such a structure, it
  33.  *    returns NULL.
  34.  */
  35. VLINK
  36. vlalloc(void)
  37.     {
  38.     VLINK    vl;
  39.     if(lfree) {
  40.         vl = lfree;
  41.         lfree = lfree->next;
  42.     }
  43.     else {
  44.         vl = (VLINK) malloc(sizeof(VLINK_ST));
  45.         if (!vl) return(NULL);
  46.         vlink_max++;
  47.     }
  48.  
  49.     vlink_count++;
  50.  
  51.     /* Initialize and fill in default values */
  52.     /* Since all but four are set to a zero-value,
  53.        why not just wipe it clean?  */
  54.     ZERO(vl);
  55.  
  56.     vl->linktype = 'L';
  57.     vl->type = stcopy("FILE");
  58.     vl->hosttype = stcopy("INTERNET-D");
  59.     vl->nametype = stcopy("ASCII");
  60.  
  61.     return(vl);
  62.     }
  63.  
  64. /*
  65.  * vlfree - free a VLINK structure
  66.  *
  67.  *    VLFREE takes a pointer to a VLINK structure and adds it to
  68.  *    the free list for later reuse.
  69.  */
  70. void
  71. vlfree(VLINK vl)
  72. //    VLINK    vl;
  73.     {
  74.         extern int string_count;
  75.  
  76.     if(vl->dontfree) return;
  77.     /* many of these don't need to call stfree(); since a check
  78.        for pointer validity's already done before even calling
  79.        it, we can just call free() here then do one big decrement
  80.        of string_count at the end.  */
  81.     if(vl->name) free(vl->name);
  82.     stfree(vl->type);
  83.     if(vl->replicas) vllfree(vl->replicas);
  84.     stfree(vl->hosttype);
  85.     if(vl->host) free(vl->host);
  86.     stfree(vl->nametype);
  87.     if(vl->filename) free(vl->filename);
  88.     if(vl->args) free(vl->args);
  89.     if(vl->lattrib) atlfree(vl->lattrib);
  90.     /* No allocation routines for f_info yet */
  91.     vl->f_info = NULL;
  92.     vl->next = lfree;
  93.     vl->previous = NULL;
  94.     lfree = vl;
  95.     vlink_count--;
  96.     string_count -= 4; /* freed name, host, filename, and args */
  97.     }
  98.  
  99. /*
  100.  * vllfree - free a VLINK structure
  101.  *
  102.  *    VLLFREE takes a pointer to a VLINK structure frees it and any linked
  103.  *    VLINK structures.  It is used to free an entrie list of VLINK
  104.  *    structures.
  105.  */
  106. void
  107. vllfree(VLINK vl)
  108. //    VLINK    vl;
  109. {
  110.     VLINK    nxt;
  111.  
  112.     while((vl != NULL) && !vl->dontfree) {
  113.         nxt = vl->next;
  114.         vlfree(vl);
  115.         vl = nxt;
  116.     }
  117. }
  118.  
  119.